package com.aurora.demo.api;

import com.aurora.demo.api.vo.SimilarImageVO;
import com.aurora.demo.service.FeatureService;
import com.aurora.demo.util.Result;
import com.aurora.demo.util.ResultGenerator;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(tags = "5. Feature相关接口")
@RestController
@RequestMapping("/feature")
public class FeatureController {

    @Autowired
    private FeatureService featureService;

    @PostMapping("/get")
    public Result<SimilarImageVO> getBySimilar(@RequestParam("file") MultipartFile file) {
        if(file == null) {
            return ResultGenerator.genFailResult("请选择要上传的图片");
        }
        if(file.getSize() > 1024 * 1024 * 10) {
            return ResultGenerator.genFailResult("上传图片不能大于10MB");
        }
        String fileName = file.getOriginalFilename();
        String suffix = fileName.substring(fileName.lastIndexOf("."), fileName.length());
        return ResultGenerator.genSuccessResult(featureService.getBySimilar(file));
    }
}
